package org.dl.gjz.menyj.controller;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName EY-CallActivityController
 * @Description org.dl.gjz.menyj.controller
 * @Author menyj
 * @Date 2025/9/1
 **/
@Slf4j
@RestController
@RequestMapping("/call_activity")
public class CallActivityController {
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private IdentityService identityService;

    /**
     *启动流程实例
     *  127.0.0.1:8088/server1/call_activity/start/Process_callactivity_main_subprocess
     */
    @GetMapping("/start/{processKey}")
    public String startProcess(@PathVariable(value = "processKey") String processKey) {
        log.info("Process: {} start", processKey);
        identityService.setAuthentication("xiaoming", null);
        VariableMap variableMap = Variables.createVariables();
        List<String> videoNames = new ArrayList<>();
        videoNames.add("电影");
        videoNames.add("电视剧");
        videoNames.add("综艺节目");
        variableMap.put("videoNames", videoNames);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
                processKey, variableMap);
        identityService.clearAuthentication(); // 3. 清除认证
        return processKey + " is Success";
    }
}
